

/**
 * 解析url参数
 * @returns {Array}
 */
function getUrlParamsCode() {
    var URLParams = new Array();
    var aParams = document.location.search.substr(1).split('&');
    for (var i = 0; i < aParams.length; i++) {
        var aParam = aParams[i].split('=');
        URLParams[aParam[0]] = decodeURI(aParam[1]);
    }
    return URLParams;
}

/**
 * 获取api头域名
 * @returns {*}
 */
function getApiDomain() {
 return "http://meiqi.api.6lapp.cn:8081";
}

/**
 * 获取数据请求post
 * @param {*} api  api地址
 * @param {*} data 数据内容
 * @param {*} that 当前指向
 */
function postAjax(api, data,callback,that){
    $.ajax({
        type:"POST",
        url:getApiDomain()+api,
        data:data,
        contentType:"application/json",
        success:function(data){
            if(data['code']==0){
                callback(data.data,that)
            }
            else{
                $.alert(data['msg'])
            }
        },
        beforeSend: function (XHR) {
            $.toast('正在初始化');
          //  XHR.setRequestHeader("token", localStorage.token);
        },
        error:function(){
            $.toast('请求数据失败');
        }
    });
}
/**
 * 获取数据请求get
 * @param {*} api  api地址
 * @param {*} data 数据内容
 * @param {*} that 当前指向
 */

function getAjax(api, data,callback,that){
    $.ajax({
        type:"POST",
        url:getApiDomain()+api+data,
        contentType:"application/json",
        success:function(data){
            if(data['code']==0){
                callback(data.data,that)
            }
            else{
                $.alert(data['msg'])
            }
        },
        beforeSend: function (XHR) {
            $.toast('正在初始化');
        
        },
        error:function(){
            $.toast('请求数据失败');
        }
    });
}

/**
 * 提示
 */
$('.toast').click(function () {
    $.toast("开发中，敬请期待！","text");
});

/**
 * 存，取 缓存变量
 */
function setStorage(key,value){
    window.localStorage.key=value
}

function getStorage(data){
    return window.localStorage.data
}


/**
 * 获取 当前时间
 */

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    if(hours >= 0 && hours <= 9){
        hours = "0" + hours;
    }
    if(minutes >= 0 && minutes <= 9){
        minutes = "0" + minutes;
    }

    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + hours + seperator2 + minutes
        + seperator2 + date.getSeconds();
    return currentdate;
}

/**
 * 扫一扫功能
 */
function getCode(data) {
    var ua = window.navigator.userAgent.toLowerCase();
    //通过正则表达式匹配ua中是否含有MicroMessenger字符串
    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
        
    }else{
        if(data=='home'){
            window.location.href='plus/barcode.html'
        }else{
            window.location.href='../plus/barcode.html'
        }
        
    }
}

function isWeiXin(){
    var ua = window.navigator.userAgent.toLowerCase();
    //通过正则表达式匹配ua中是否含有MicroMessenger字符串
    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
        return 'wx'
    }else{
        return 'app';
    }
  }


  function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    return currentdate;
}

function get7FormatDate(aa){
    var date1 = new Date(),
    time1=date1.getFullYear()+"-"+(date1.getMonth()+1)+"-"+date1.getDate();//time1表示当前时间
    var date2 = new Date(date1);
    date2.setDate(date1.getDate()+aa);
    var month = date2.getMonth() + 1;
    var strDate = date2.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var time2 = date2.getFullYear()+"-"+month+"-"+strDate+" "+date2.getHours()+':'+date2.getMinutes()+':'+date2.getSeconds();
    return time2
}